<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <style>
        #gridTable tr td {
            text-align: center;
        }
        #gview_gridTable thead tr th .ui-jqgrid-sortable {
            text-align: center;
        }
        /*转成省略号*/
        /*.ui-jqgrid tr.jqgrow td { text-overflow : ellipsis; }*/
        /*.ui-jqgrid tr.jqgrow td {*/
        /*white-space: normal !important;*/
        /*height: 35px;*/
        /*vertical-align: text-top;*/
        /*padding-top: 2px;*/
        /*}*/
        /*#gview_gridTable .ui-jqgrid-bdiv {*/
        /*max-height: 450px;*/
        /*!important;*/
        /*}*/
        /*.nav > li > a:focus, .nav > li > a:hover {*/
            /*text-decoration: none;*/
            /*background-color: #33CCFF !important;*/
        /*}*/
    </style>
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
</head>
<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <%--表格头部功能按钮--%>
        <div class="row search-row" style="margin-top: 10px; margin-left: 8px  !important;">
            <div class="col-xs-2">
                <input type="text" class="form-control" style="margin: 3px 0px;" id="searchWord" placeholder="请输入要搜索的关键词"/>
            </div>
            <div class="col-xs-10" style="right: 30px;">
                <div class="col-xs-12">
                    <button class="btn btn-sm btn-primary" id="queryIndexCz">搜索</button>
                    <button class="btn btn-sm btn-info clickMe" id="addIndexCz">添加</button>
                    <button class="btn btn-sm btn-info clickMe" id="delIndexCz">删除</button>
                    <button class="btn btn-sm btn-info clickMe" id="editIndexCz">修改</button>
                    <input class="btn btn-sm btn-default" style="display:inline;" type="file" name="file"
                           id="file" accept=".xlsx">
                    <button class="btn btn-sm btn-success upload" id="importIndexCz">导入</button>
                    <button class="btn btn-sm btn-success" id="exportIndexCz">导出</button>
                </div>
            </div>
        </div>
        <div class="main-content-inner">
            <div class="page-content">
                <!-- /section:settings.box -->
                <%--<div class="row">--%>
                    <%--<div class="col-xs-12">--%>
                        <%--<div class="pull-left">--%>
                            <%--<shiro:hasPermission name="web:index:query">--%>
                                <%--<button class="btn btn-sm btn-info" id="query">查询</button>--%>
                            <%--</shiro:hasPermission>--%>
                            <%--<shiro:hasPermission name="web:index:query">--%>
                                <%--<button class="btn btn-sm btn-info" id="print">打印</button>--%>
                            <%--</shiro:hasPermission>--%>
                            <%--&lt;%&ndash;<input class="btn btn-sm btn-default" style="display:inline;" type="file" name="file"&ndash;%&gt;--%>
                                   <%--&lt;%&ndash;id="file" accept=".xls">&ndash;%&gt;--%>
                            <%--<button class="btn btn-sm btn-success upload" id="importIndicatorBreakdown"--%>
                                    <%--data-id="import">导入--%>
                            <%--</button>--%>
                        <%--</div>--%>
                    <%--</div>--%>
                <%--</div>--%>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!-- jqGrid表格 -->
                        <table id="gridTable"></table>
                        <!-- jqGrid工具类 -->
                        <div id="gridPager"></div>
                        <!-- 查询对话框 -->
                        <div style="display: none;">
                            <div class="row" id="queryDialog"></div>
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>

    <!-- dialog -->
    <%@ include file="/WEB-INF/views/include/dialog.jsp" %>
</div><!-- /.main-container -->

<!-- footer -->
<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<script src="<s:url value="/assets/js/jquery.printFinal.js"></s:url>"></script>
<script src="<s:url value="/assets/js/ajaxfileupload.js"></s:url>"></script>
<script type="text/javascript">
    //基本路径
    var baseUrl = "<s:url value="/web/index"></s:url>/"

    //jqgrid的表格高度
    var height = 320;
    //jqgrid表格行头的中文
    var colNames = ['', '指标名称', '指标年份', '指标等级', '牵头单位', '责任单位', '乡镇', '分管领导', '指标时间类型', '企业名称'];
    //jqgrid表格中每一行的信息模型
    var colModel = [
        {name: 'sysId', index: 'sysId', hidden: true, key: true},
        {name: 'indexName', index: 'indexName', width: 60, editable: true},
        {name: 'datetime', index: 'datetime', width: 60, editable: true},
        {name: 'indexLevel', index: 'indexLevel', width: 60, editable: true, formatter: indexLevelFmatter},
        {name: 'leadDept', index: 'leadDept', width: 60, editable: true},
        {name: 'respDept', index: 'respDept', width: 60, editable: true},
        {name: 'town', index: 'town', width: 60, editable: true},
        {name: 'leader', index: 'leader', width: 60, editable: true},
        {name: 'dateUnit', index: 'dateUnit', width: 60, editable: true, formatter: dateUnitFmatter},
        {name: 'enterpriseName', index: 'enterpriseName', width: 60, editable: true}
    ];

    //jqgrid的具体执行方法
    jqgrid({
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager"
    });

    //加载查询对话框
    //$("#queryDialog").load(getUrl("filter"));

    //显示查询对话框
    var queryDialog = $("#queryDialog");

    //重置表单
    function reset() {
        resetForm("#formDialog form");
    }

    $("#chart").click(function () {
        var url = '<s:url value="/modules/sys/log/chart"></s:url>';
        window.parent.openapp(url, 'sysLogChart', '日志报表');
    });

    function indexLevelFmatter(cellvalue, options, rowObject) {
        return cellvalue + "级指标";
    }

    function dateUnitFmatter(cellvalue, options, rowObject) {
        /*1 月度，2 季度，3 年度*/
        if (cellvalue == "1") {
            return "月度指标";
        } else if (cellvalue == "2") {
            return "季度指标";
        } else if (cellvalue == "3") {
            return "年度指标";
        } else {
            return "";
        }
    }

    // $("#print").click(function () {
    //     showDialog({
    //         dialogTitle: '打印预览',
    //         dialogBody: $("#gridTable").html(),
    //         dialogFoot: "<button type='button' class='btn btn-pink' onclick='print()'>打印</button>" +
    //             "<button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button>"
    //     });
    // });
    // function print() {
    //     $("#gridTable").printFinal({
    //         preview: false,//打印预览
    //         impcss: true//引入css文件
    //     });
    // }

    //上传
    $(".upload").click(function () {
        //debugger;
        var fileval = $(this).prev().val();
        console.log(fileval);
        var fileId = $(this).prev().attr("id");
        console.log(fileId);
        if (fileval == null || fileval == "") {
            alert("未选择任何文件");
            return;
        }
        $("#dialog").show();
        $.ajaxFileUpload({
            type: "post",
            fileElementId: fileId,
            secureuri: false,
            dataType: 'json',
            url: "/web/index/import",
            async: true,
            success: function (data) {
                if (data.code == "200") {
                    alert("数据导入成功");
                    seachJqgird("#gridTable", "#formDialog form");
                } else if (data.code == "500") {
                    alert(data.data);
                } else {
                    alert("数据导入成功 ！！请联系管理员");
                }
            }
        });
    });

    /*======================================添加指标======================================*/
    $("#addIndexCz").click(function () {
        loadDialog({
            dialogTitle: '添加指标',
            dialogUrl: getUrl("addIndexCz"),
            dialogFoot: '<button id="submit" type="button" class="btn btn-primary" onclick="addIndexCz()">确认添加</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });
    function addIndexCz() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("addIndexCz"),
            tableId: "#gridTable",
            successMessage: "添加成功",
            successTitle: '操作对话框',
            //failMessage: '更新失败',
            failTitle: '消息对话框'
        });
    }

    /*======================================删除财政指标======================================*/
    $("#delIndexCz").click(function () {
        showDeleteDialog({
            url: getUrl("delIndexCz"),
            tableId: "#gridTable",
            confirmTitle: "删除财政指标",
            confirmMessage: "是否确定删除?",
            confirmOk: "确定",
            confirmCancel: "取消",
            successMessage: "删除成功",
            successTitle: "消息对话框",
            failMessage: "删除失败",
            failTitle: "消息对话框",
            errorTitle: "警告提示框",
            errorMessage: "您当前尚未选中一行，请选择后再试",
            errorOk: "确定"
        });
    });

    /*======================================修改指标目标======================================*/
    //修改指标目标
    $("#editIndexCz").click(function () {
        showEditView();
    });
    //显示编辑对话框
    function showEditView() {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "任务详情",
            dialogUrl: getUrl("editIndexCz"),
            dialogFoot: '<button id="submit" type="button" class="btn btn-primary" onclick="editIndexCz()">确认修改</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    }

    //执行更新操作
    function editIndexCz() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("editIndexCz"),
            tableId: "#gridTable",
            successMessage: "修改成功",
            successTitle: '操作对话框',
            //failMessage: '更新失败',
            failTitle: '消息对话框'
        });
    }

</script>
</body>
</html>